<?php

class Core_Backend_Component_Promotion_View_Concessions_Index extends Core_Backend_Share_View_Grid {
	
	protected function initialize(){
		parent::initialize();
		$this->setTemplatePath('index');
	}

    protected function buildToolbar($toolbar) {
        parent::buildToolbar($toolbar);
        if ($this->getIdentity()->isAllowAction('promotion_concessions_review')) {
            $group = $toolbar->createGroup('status');
            $group->addButton($this->__('share.button.publish'))
                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'published'), 'review') . "')");
            $group->addButton($this->__('share.button.forbid'))
                    ->bindEvent('click', "forbidGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'forbidden'), 'review') . "')");
        }

        $group = $toolbar->createGroup();
        $group->addLink($this->getUrl(NULL, 'create'), $this->__('share.button.create'));
        if ($this->getIdentity()->isAllowAction('promotion_concessions_import')) {
            $group->addLink($this->getUrl(NULL, 'import'), $this->__('share.button.import'));
//            $group->addLink($this->getUrl(NULL, 'generate-tag'), $this->__('share.button.generate_tag'));
        }
    }

    protected function buildGrid($grid) {
        $filter = new Kd_Object($this->getRequest()->getParameter('filter'));
        $grid->setId('concessions_grid')
                ->setPrimaryKey('id')
                ->setAllowFilter(TRUE)
                ->setSortField($this->getRequest()->getParameter('sort', 'id'))
                ->setSortDirection($this->getRequest()->getParameter('dir', 'asc'))
                ->setSortUrlFormat($this->getSortUrl());
        $grid->addLabelColumn($this->__('share.label.name'), 'name', '{name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('name'))
                ->setSortField('name')
                ->setWidth(150);
        $grid->addLabelColumn($this->__('promotion.label.category'), 'categoryname', '{category_name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('categoryname'))
                ->setSortField('category_id')
                ->setWidth(150);
//        $grid->addLabelColumn('POI', 'poi', '{poi_ids}')
//             ->setTextboxFilter(NULL, NULL, $filter->getData('poi'))
//             ->setSortField('category_id')
//             ->setWidth(180);
        $grid->addDatetimeColumn($this->__('share.label.start_time'), 'starttime', '{start_time}')
                ->setSortField('start_time')
                ->setWidth(100);
        $grid->addDatetimeColumn($this->__('share.label.end_time'), 'endtime', '{end_time}')
                ->setSortField('end_time')
                ->setWidth(100);
        $grid->addLabelColumn($this->__('share.label.tag'), 'tag', '{tag}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('tag'))
                ->setWidth(300);
        $grid->addLabelColumn($this->__('share.label.status'), 'status', '{{lang "status.publication.{status}"}}')
                ->setSelectFilter(NULL, NULL, Kd_Localize_Helper::getLanguageItems('status.publication'), NULL, NULL, $filter->getData('status'))
                ->setWidth(60)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getList()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        parent::buildPagination($pagination);
        $pagination->setUrlFormat($this->getPaginationUrl())
                ->setRecordCount($this->getRecords());
    }

}